<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: Retreval::QueryResultSet</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/retreval/query_result_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/retreval/query_result.rb">lib/retreval/query_result.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-i-add_result">#add_result</a></li>
					
					<li><a href="#method-i-load_from_yaml_file">#load_from_yaml_file</a></li>
					
					<li><a href="#method-i-mean_average_precision">#mean_average_precision</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
				
					<li class="file"><a href="../TODO.html">TODO</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../Retreval.html">Retreval</a></li>
				
					<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
				
					<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
				
					<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
				
					<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
				
					<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
				
					<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
				
					<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
				
					<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
				
					<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
				
					<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
				
					<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
				
					<li><a href="../Retreval/User.html">Retreval::User</a></li>
				
					<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
				
					<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">Retreval::QueryResultSet</h1>

		<div id="description">
			<p>
A <a href="QueryResultSet.html">QueryResultSet</a> combines multiple
QueryResults and stores them. It is possible to load a set of QueryResults
from a YAML file.
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		
		<div id="attribute-method-details" class="method-section section">
			<h3 class="section-header">Attributes</h3>

			
			<div id="query-results-attribute-method" class="method-detail">
				<a name="query_results"></a>
				
				<div class="method-heading attribute-method-heading">
					<span class="method-name">query_results</span><span
						class="attribute-access-type">[R]</span>
				</div>

				<div class="method-description">
				
				
				
				</div>
			</div>
			
		</div>
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(args)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Creates a new <a href="QueryResultSet.html">QueryResultSet</a>, with a
specified <a href="GoldStandard.html">GoldStandard</a> Called by:
</p>
<pre>
    QueryResultSet.new :gold_standard =&gt; my_gold_standard</pre>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 15</span>
15:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
16:       <span class="ruby-ivar">@query_results</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
17:       <span class="ruby-ivar">@gold_standard</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:gold_standard</span>]
18:       <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Can not create a Query Result set without a gold standard that they belong to&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:gold_standard</span>].<span class="ruby-identifier">nil?</span>
19:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="add-result-method" class="method-detail ">
				<a name="method-i-add_result"></a>

				<div class="method-heading">
				
					<span class="method-name">add_result</span><span
						class="method-args">(result)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Adds a <a href="QueryResult.html">QueryResult</a> to the list of results
for this set
</p>
					

					
					<div class="method-source-code"
						id="add-result-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 72</span>
72:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_result</span>(<span class="ruby-identifier">result</span>)
73:       <span class="ruby-ivar">@query_results</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">result</span>
74:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="load-from-yaml-file-method" class="method-detail ">
				<a name="method-i-load_from_yaml_file"></a>

				<div class="method-heading">
				
					<span class="method-name">load_from_yaml_file</span><span
						class="method-args">(file)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Parses a YAML file containing many result sets, either ranked or unranked.
The file should look like this:
</p>
<pre>
    * query: Test query
      ranked: true
      documents:
          * id: first_document.txt
            score: 95
          * id: second_document.txt
            score: 38
    * query: Second query
      ranked: true
      documents:
          * id: another_doc.txt
            score: 12
          * id: yet_another_one.txt
            score: 1
</pre>
<p>
&#8230; and so on.
</p>
					

					
					<div class="method-source-code"
						id="load-from-yaml-file-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 38</span>
38:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_from_yaml_file</span>(<span class="ruby-identifier">file</span>)
39:       <span class="ruby-keyword kw">begin</span>
40:         
41:         <span class="ruby-identifier">ydoc</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>, <span class="ruby-value str">&quot;r&quot;</span>))
42:         
43:         <span class="ruby-identifier">ydoc</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span>
44:           <span class="ruby-identifier">query</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">&quot;query&quot;</span>]          <span class="ruby-comment cmt"># =&gt; the query string</span>
45:           <span class="ruby-identifier">ranked</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">&quot;ranked&quot;</span>]        <span class="ruby-comment cmt"># =&gt; a boolean flag if ranked or not</span>
46:           <span class="ruby-identifier">documents</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">&quot;documents&quot;</span>]  <span class="ruby-comment cmt"># =&gt; an array of documents</span>
47:           
48:           <span class="ruby-comment cmt"># Determine whether this will be a ranked or unranked result set</span>
49:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ranked</span>
50:             <span class="ruby-identifier">resultset</span> = <span class="ruby-constant">RankedQueryResult</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:query</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">query</span>, <span class="ruby-value">:gold_standard</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@gold_standard</span>
51:           <span class="ruby-keyword kw">else</span>
52:             <span class="ruby-identifier">resultset</span> = <span class="ruby-constant">UnrankedQueryResult</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:query</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">query</span>, <span class="ruby-value">:gold_standard</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@gold_standard</span>
53:           <span class="ruby-keyword kw">end</span>
54:           
55:           <span class="ruby-comment cmt"># Find all documents for this query result</span>
56:           <span class="ruby-identifier">documents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">document_element</span><span class="ruby-operator">|</span>
57:             <span class="ruby-identifier">document</span> = <span class="ruby-identifier">document_element</span>[<span class="ruby-value str">&quot;id&quot;</span>]
58:             <span class="ruby-identifier">score</span> = <span class="ruby-identifier">document_element</span>[<span class="ruby-value str">&quot;score&quot;</span>]
59:             <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">add_document</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">document</span>, <span class="ruby-value">:score</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">score</span>
60:           <span class="ruby-keyword kw">end</span>
61:           
62:           <span class="ruby-ivar">@query_results</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">resultset</span>
63:           
64:         <span class="ruby-keyword kw">end</span>
65:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
66:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Error while parsing the YAML document: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
67:       <span class="ruby-keyword kw">end</span>
68:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mean-average-precision-method" class="method-detail ">
				<a name="method-i-mean_average_precision"></a>

				<div class="method-heading">
				
					<span class="method-name">mean_average_precision</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Calculates the Mean Average Precision for each <a
href="RankedQueryResult.html">RankedQueryResult</a> in this set. This
method should only be called when all sets have been calculated, or else it
will take a really long time to perform all necessary calculations.
</p>
					

					
					<div class="method-source-code"
						id="mean-average-precision-source">
<pre>
    <span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 79</span>
79:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mean_average_precision</span>
80:       <span class="ruby-identifier">total_ranked_query_results</span> = <span class="ruby-ivar">@query_results</span>.<span class="ruby-identifier">count</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">result</span><span class="ruby-operator">|</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RankedQueryResult</span> }
81:       <span class="ruby-ivar">@mean_average_precision</span> = <span class="ruby-ivar">@query_results</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0.0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">result</span><span class="ruby-operator">|</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RankedQueryResult</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">average_precision</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">sum</span> } <span class="ruby-operator">/</span> <span class="ruby-identifier">total_ranked_query_results</span>
82:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

